home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / vidhrdw / tsamurai.c < prev    next >
C/C++ Source or Header  |  2000-04-04  |  6KB  |  254 lines

  1. /*
  2. **    Video Driver for Taito Samurai (1985)
  3. */
  4.  
  5. #include "driver.h"
  6. #include "vidhrdw/generic.h"
  7.  
  8. /*
  9. ** prototypes
  10. */
  11. WRITE_HANDLER( tsamurai_bgcolor_w );
  12. WRITE_HANDLER( tsamurai_flipscreen_w );
  13. WRITE_HANDLER( tsamurai_textbank_w );
  14. WRITE_HANDLER( tsamurai_scrolly_w );
  15. WRITE_HANDLER( tsamurai_scrollx_w );
  16.  
  17. WRITE_HANDLER( tsamurai_bg_videoram_w );
  18. WRITE_HANDLER( tsamurai_fg_videoram_w );
  19.  
  20. void tsamurai_convert_color_prom(unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom);
  21. void tsamurai_vh_screenrefresh( struct osd_bitmap *bitmap, int fullrefresh );
  22. int tsamurai_vh_start( void );
  23.  
  24. /*
  25. ** variables
  26. */
  27. unsigned char *tsamurai_videoram;
  28. static int flipscreen;
  29. static int bgcolor;
  30. static int textbank;
  31.  
  32. static struct tilemap *background, *foreground;
  33.  
  34.  
  35. /*
  36. ** color prom decoding
  37. */
  38.  
  39. void tsamurai_convert_color_prom(unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom)
  40. {
  41.     int i;
  42.  
  43.     for (i = 0;i < Machine->drv->total_colors;i++)
  44.     {
  45.         int bit0,bit1,bit2,bit3;
  46.  
  47.  
  48.         /* red component */
  49.         bit0 = (color_prom[0] >> 0) & 0x01;
  50.         bit1 = (color_prom[0] >> 1) & 0x01;
  51.         bit2 = (color_prom[0] >> 2) & 0x01;
  52.         bit3 = (color_prom[0] >> 3) & 0x01;
  53.         *(palette++) = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
  54.         /* green component */
  55.         bit0 = (color_prom[Machine->drv->total_colors] >> 0) & 0x01;
  56.         bit1 = (color_prom[Machine->drv->total_colors] >> 1) & 0x01;
  57.         bit2 = (color_prom[Machine->drv->total_colors] >> 2) & 0x01;
  58.         bit3 = (color_prom[Machine->drv->total_colors] >> 3) & 0x01;
  59.         *(palette++) = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
  60.         /* blue component */
  61.         bit0 = (color_prom[2*Machine->drv->total_colors] >> 0) & 0x01;
  62.         bit1 = (color_prom[2*Machine->drv->total_colors] >> 1) & 0x01;
  63.         bit2 = (color_prom[2*Machine->drv->total_colors] >> 2) & 0x01;
  64.         bit3 = (color_prom[2*Machine->drv->total_colors] >> 3) & 0x01;
  65.         *(palette++) = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
  66.  
  67.         color_prom++;
  68.     }
  69. }
  70.  
  71.  
  72. /***************************************************************************
  73.  
  74.   Callbacks for the TileMap code
  75.  
  76. ***************************************************************************/
  77.  
  78. static void get_bg_tile_info(int tile_index)
  79. {
  80.     unsigned char attributes = tsamurai_videoram[2*tile_index+1];
  81.     int color = (attributes&0x1f);
  82.     SET_TILE_INFO(0,tsamurai_videoram[2*tile_index]+4*(attributes&0xc0),color )
  83. }
  84.  
  85. static void get_fg_tile_info(int tile_index)
  86. {
  87.     int tile_number = videoram[tile_index];
  88.     if( textbank&1 ) tile_number += 256;
  89.     SET_TILE_INFO(1,tile_number,colorram[((tile_index&0x1f)*2)+1] & 0x1f )
  90. }
  91.  
  92.  
  93. /***************************************************************************
  94.  
  95.   Start the video hardware emulation.
  96.  
  97. ***************************************************************************/
  98.  
  99. int tsamurai_vh_start(void)
  100. {
  101.     background = tilemap_create(get_bg_tile_info,tilemap_scan_rows,TILEMAP_TRANSPARENT,8,8,32,32);
  102.     foreground = tilemap_create(get_fg_tile_info,tilemap_scan_rows,TILEMAP_TRANSPARENT,8,8,32,32);
  103.  
  104.     if (!background || !foreground)
  105.         return 1;
  106.  
  107.     background->transparent_pen = 0;
  108.     foreground->transparent_pen = 0;
  109.     return 0;
  110. }
  111.  
  112.  
  113. /***************************************************************************
  114.  
  115.   Memory handlers
  116.  
  117. ***************************************************************************/
  118.  
  119. WRITE_HANDLER( tsamurai_scrolly_w )
  120. {
  121.     tilemap_set_scrolly( background, 0, data );
  122. }
  123.  
  124. WRITE_HANDLER( tsamurai_scrollx_w )
  125. {
  126.     tilemap_set_scrollx( background, 0, data );
  127. }
  128.  
  129. WRITE_HANDLER( tsamurai_bgcolor_w )
  130. {
  131.     bgcolor = data;
  132. }
  133.  
  134. WRITE_HANDLER( tsamurai_flipscreen_w )
  135. {
  136.     if( flipscreen!=data )
  137.     {
  138.         flipscreen = data;
  139.         tilemap_set_flip( ALL_TILEMAPS, flipscreen?(TILEMAP_FLIPX | TILEMAP_FLIPY):0 );
  140.     }
  141. }
  142.  
  143. WRITE_HANDLER( tsamurai_textbank_w )
  144. {
  145.     if( textbank!=data )
  146.     {
  147.         textbank = data;
  148.         tilemap_mark_all_tiles_dirty( foreground );
  149.     }
  150. }
  151.  
  152. WRITE_HANDLER( tsamurai_bg_videoram_w )
  153. {
  154.     if( tsamurai_videoram[offset]!=data )
  155.     {
  156.         tsamurai_videoram[offset]=data;
  157.         offset = offset/2;
  158.         tilemap_mark_tile_dirty(background,offset);
  159.     }
  160. }
  161. WRITE_HANDLER( tsamurai_fg_videoram_w )
  162. {
  163.     if( videoram[offset]!=data )
  164.     {
  165.         videoram[offset]=data;
  166.         tilemap_mark_tile_dirty(foreground,offset);
  167.     }
  168. }
  169. WRITE_HANDLER( tsamurai_fg_colorram_w )
  170. {
  171.     if( colorram[offset]!=data )
  172.     {
  173.         colorram[offset]=data;
  174.         if (offset & 1)
  175.         {
  176.             int col = offset/2;
  177.             int row;
  178.             for (row = 0;row < 32;row++)
  179.                 tilemap_mark_tile_dirty(foreground,32*row+col);
  180.         }
  181.     }
  182. }
  183.  
  184.  
  185. /***************************************************************************
  186.  
  187.   Display refresh
  188.  
  189. ***************************************************************************/
  190.  
  191. static void draw_sprites( struct osd_bitmap *bitmap )
  192. {
  193.     struct GfxElement *gfx = Machine->gfx[2];
  194.     const struct rectangle *clip = &Machine->drv->visible_area;
  195.     const unsigned char *source = spriteram+32*4-4;
  196.     const unsigned char *finish = spriteram; /* ? */
  197.     static int flicker;
  198.     flicker = 1-flicker;
  199.  
  200.     while( source>=finish )
  201.     {
  202.         int attributes = source[2]; /* bit 0x10 is usually, but not always set */
  203.  
  204.         int sx = source[3] - 16;
  205.         int sy = 240-source[0];
  206.         int sprite_number = source[1];
  207.         int color = attributes&0x1f;
  208.         //color = 0x2d - color; nunchakun fix?
  209.         if( sy<-16 ) sy += 256;
  210.  
  211.         if( flipscreen )
  212.         {
  213.             drawgfx( bitmap,gfx,
  214.                 sprite_number&0x7f,
  215.                 color,
  216.                 1,(sprite_number&0x80)?0:1,
  217.                 256-32-sx,256-32-sy,
  218.                 clip,TRANSPARENCY_PEN,0 );
  219.         }
  220.         else
  221.         {
  222.             drawgfx( bitmap,gfx,
  223.                 sprite_number&0x7f,
  224.                 color,
  225.                 0,sprite_number&0x80,
  226.                 sx,sy,
  227.                 clip,TRANSPARENCY_PEN,0 );
  228.         }
  229.  
  230.         source -= 4;
  231.     }
  232. }
  233.  
  234. void tsamurai_vh_screenrefresh( struct osd_bitmap *bitmap, int fullrefresh )
  235. {
  236.     tilemap_update( ALL_TILEMAPS );
  237.     tilemap_render( ALL_TILEMAPS );
  238.  
  239.     /*
  240.         This following isn't particularly efficient.  We'd be better off to
  241.         dynamically change every 8th palette to the background color, so we
  242.         could draw the background as an opaque tilemap.
  243.  
  244.         Note that the background color register isn't well understood
  245.         (screenshots would be helpful)
  246.     */
  247.     fillbitmap( bitmap, Machine->pens[bgcolor], 0 );
  248.     tilemap_draw( bitmap, background, 0 );
  249.  
  250.     draw_sprites( bitmap );
  251.  
  252.     tilemap_draw( bitmap, foreground, 0 );
  253. }
  254.